package de.velvettear.squirrel.kernel;

import java.util.HashMap;
import java.util.Vector;

import android.database.Cursor;
import de.velvettear.squirrel.database.Column;
import de.velvettear.squirrel.database.Column.ColumnDataType;

public class Settings extends Base {

	public final static String TABLENAME = "Settings";
	
	public String m_sValue = "";
	
	public Settings() {
		
	}
	
	public String getTableName() {
		return TABLENAME;
	}
		
	public Vector<Settings> getSettingsByName(String m_sName) {
		return select("m_sName = '" + m_sName + "'", null, false);
	}
	
	public String getValueByName(String m_sName) {
		String value = "";
		
		Vector<Settings> settings = (Vector<Settings>) select("m_sName = '" + m_sName + "'", null, false);
		if (settings.size() > 0) {
			Settings setting = settings.elementAt(0);
			if (setting.isValid()) {
				value = setting.m_sValue;
			}			
		}
		
		return value;
	}
	
	public HashMap<String,Object> getData() {
		HashMap<String, Object> retVal = super.getData();
		retVal.put("m_sValue", this.m_sValue);
		return retVal;  
	}
	
	public void setData(Cursor c) {		   
		super.setData(c);
		this.m_sValue = c.getString(c.getColumnIndex("m_sValue"));
	}
	
	public static Vector<Column> getColumnConfig() {                          
		Vector<Column> retVal = Base.getColumnConfig();                    
                                                                                
		retVal.add(new Column("m_sValue", 4000,	false, ColumnDataType.sql_varchar));	
		
		return retVal;																   
	}	
	
}
